(function($){
    var show = function(aHtml, opt){
        aHtml = aHtml.replace("#{title}",opt.title).replace("#{text}",opt.text).replace("#{yesBtn}",opt.yesBtn).replace("#{noBtn}",opt.noBtn);
        var al = $(aHtml);
        al.find(".close,.no").on("click",function(){
            al.remove();
            opt.no();
        });
        al.find(".yes").on("click",function(){
            al.remove();
            opt.yes();
        });
        al.find(".title").on({
            mousedown: function (e) {

                var el2 = $(this);
                var el = el2.parent();
                el.css("transition", "all 0s");
                var os = el.offset();
                var dx = e.pageX - os.left, dy = e.pageY - os.top;
                $(document).on('mousemove.drag', function (e) {
                    el.offset({top: e.pageY - dy, left: e.pageX - dx});
                });
            },
            mouseup: function (e) {
                $(document).off('mousemove.drag');
            }
        });
        $("body").append(al)
        var ah = al.find('.alert').height();
        al.find('.alert').css("top", "50%");
        al.find('.alert').css("margin-top", "-"+(ah/2)+"px");
    }
    var jjalert = function(opt){
        var aHtml = '<div class="jj-alert">'+
            '<div class="hide"></div>'+
            '<div class="alert">'+
            '<div class="title">'+
            '<label class="label">#{title}</label>'+
            '<span class="close">×</span>'+
            '</div>'+
            '<div class="info">'+
            '<div class="icon"></div>'+
            '<div class="text">#{text}</div>'+
            '</div>'+
            '<div class="btn">'+
            '<button class="yes">#{yesBtn}</button>'+
            '</div>'+
            '</div>'+
            '</div>';
        show(aHtml, opt);
    }
    var jjconfirm=function(opt){

        var aHtml = '<div class="jj-alert">'+
            '<div class="hide"></div>'+
            '<div class="alert">'+
            '<div class="title">'+
            '<label class="label">#{title}</label>'+
            '<span class="close">×</span>'+
            '</div>'+
            '<div class="info">'+
            '<div class="icon"></div>'+
            '<div class="text">#{text}</div>'+
            '</div>'+
            '<div class="btn">'+
            '<button class="yes">#{yesBtn}</button>'+
            '<button class="no">#{noBtn}</button>'+
            '</div>'+
            '</div>'+
            '</div>';
        show(aHtml, opt);
    }
    var options = {
        title:"通知",
        text:"",
        yesBtn : "确定",
        noBtn:"取消",
        yes:function(){

        },
        no:function(){

        }
    };

    $.extend({
        jjalert:function(opt) {
            var opt2 = $.extend({}, options, opt||{});
            if(typeof opt == 'string'){
                opt2.text = opt;
            }
            jjalert(opt2);
        },
        jjconfirm:function(opt) {
            var opt2 = $.extend({}, options, opt||{});
            if(typeof opt == 'string'){
                opt2.title='警告';
                opt2.text = opt;
            }
            jjconfirm(opt2);
        }
    });
})(jQuery);




(function($){
	var options = {
	        html:'<div class="jj-postion"><div class="jj-info"></div></div>'
	    };

    var jjinfo = function(obj, ret){
    	var $retObj = null;
        var $tempDiv = $('<div style="overflow: hidden; width: 0; height: 0; position: absolute; top: 0; left: 0;"></div>'); //用于测量弹出层的隐藏div
    	$(obj).hover(function(evt){
    		$retObj = $(options.html);
    		$retObj.find(".jj-info").html(ret);
            
            //添加到隐藏的div中进行测量高度
            $tempDiv.append($retObj);
            $(document.body).append($tempDiv);
            var winH = $(window).height();
            var offset4bottom = winH - evt.clientY;
            var retObjH = $retObj.height();
            if (retObjH > offset4bottom) {
            	$retObj.css({
            		bottom : 0
            	});
            }
            
            $tempDiv.remove();
    		$(obj).append($retObj)
    	},function(){
    		if($retObj != null){
    			$retObj.remove();
    		}
    	})
    }
    $.fn.extend({
    	jjinfo:function(opt){
        	this.each(function(){
        		jjinfo(this, opt);
            });
        }
    });
})(jQuery);